using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using Lilium.Web.Mvc.AjaxControlToolkit.NumericUpDown;
using Lilium.Web.Mvc.AjaxControlToolkit;

namespace Samples.Controllers
{
	public class NumericUpDownController: Controller
	{
		//
		// GET: /NumericUpDown/

		public ActionResult NextValue(NumericUpDownValueRequest request)
		{
			if (request == null)
				throw new ArgumentNullException("request");

			var value = new Random().Next(Math.Min(1000, Math.Max(0, request.Current)), 1001);
			return Json(NumericUpDownExtender.CreateNumericUpDownValue(value));
		}

		public ActionResult PrevValue(NumericUpDownValueRequest request)
		{
			if (request == null)
				throw new ArgumentNullException("request");

			var value = new Random().Next(0, Math.Min(1000, Math.Max(0, request.Current)));
			return Json(NumericUpDownExtender.CreateNumericUpDownValue(value));
		}

		public ActionResult Index(int? value1, int? value2, int? random, string month)
		{
			bool hasAllValues = true;
			if (value1 == null)
			{
				ViewData["value1"] = 3;
				hasAllValues = false;
			}
			if (value2 == null)
			{
				ViewData["value2"] = 0;
				hasAllValues = false;
			}
			if (random == null)
			{
				ViewData["random"] = 500;
				hasAllValues = false;
			}
			if (string.IsNullOrEmpty(month))
			{
				ViewData["month"] = "June";
				hasAllValues = false;
			}
			if (hasAllValues && ((Request.HttpMethod != "GET") || (Request.IsAjaxRequest())))
				ViewData["ResponseText"] = string.Format(
					"Value: <b>{0}</b><br>Month: <b>{1}</b><br>Random Value: <b>{2}</b><br>Value: <b>{3}</b>",
					value1, month, random, value2);
			else
				ViewData["ResponseText"] = "[No response provided yet]";
			if (!Request.IsAjaxRequest())
				return View();
			else
				return PartialView("Response");
		}
	}
}
